<?php
echo '<div>Start update database</div><ul id="action">';
define('DEBUG_SQL',true);
define('DEBUG_SQL_SHOW_QUERY',true);
define('DEBUG_SQL_STOP_SCRIPT',true);
$db->sql_query("ALTER TABLE `immo_annonce` ADD `nb_vue` INT( 10 ) NOT NULL DEFAULT '0'");
echo '<li>Table immo_annonce modifiee</li>';
$db->sql_query("
CREATE TABLE `immo_plugins` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 100 ) NOT NULL ,
`fichier` VARCHAR( 100 ) NOT NULL ,
`version` VARCHAR( 10 ) NOT NULL ,
`date_install` INT( 20 ) NOT NULL ,
`date_version` INT( 20 ) NOT NULL ,
`actif` INT( 1 ) NOT NULL ,
`install` INT( 1 ) NOT NULL ,
`auteur` VARCHAR( 100 ) NOT NULL ,
`description_short` VARCHAR( 150 ) NOT NULL
) ENGINE = MYISAM ;");
$db->sql_query("ALTER TABLE `immo_plugins` CHANGE `date_version` `date_version` VARCHAR( 100 ) NOT NULL");
echo '<li>Table immo_plugins creee</li>';
#
# Creation table menu navigation
#
$db->sql_query("CREATE TABLE `immo_menu_navigation` (
`id` INT NULL AUTO_INCREMENT PRIMARY KEY ,
`titre` VARCHAR( 75 ) NOT NULL ,
`lien` VARCHAR( 200 ) NOT NULL ,
`ordre` INT( 10 ) NOT NULL ,
`actif` INT( 2 ) NOT NULL ,
`description` VARCHAR( 100 ) NOT NULL
) ENGINE = MYISAM ;");
echo '<li>Table immo_menu_navigation creee</li>';
#
# Insertion contenue
#
$db->sql_query("
INSERT INTO `immo_menu_navigation` (`id`, `titre`, `lien`, `ordre`, `actif`, `description`) VALUES
(1, 'Accueil', 'index.php', 0, 1, 'Accueil'),
(2, 'Toutes nos annonces', 'annonce.php', 1, 1, 'Toutes nos annonces'),
(3, 'Maison', 'annonce.php?type=1', 2, 1, 'Maison'),
(4, 'Appartement', 'annonce.php?type=2', 3, 1, 'Appartement'),
(5, 'Terrain', 'annonce.php?type=3', 4, 1, 'Terrain'),
(6, 'Location', 'annonce.php?type=4', 6, 1, 'Location'),
(7, 'Commerce', 'annonce.php?type=5', 5, 1, 'Commerce'),
(8, 'Autre', 'annonce.php?type=99', 7, 1, 'Autre'),
(9, 'Agence', 'agence.php', 8, 1, 'Nos agences'),
(10, 'Contact', 'contact.php', 9, 1, 'Nous contacter');");
echo '<li>Donne ajoute dans la table immo_menu_navigation</li>';
#
# Table bloc
#
$db->sql_query("
CREATE TABLE `immo_bloc` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 100 ) NOT NULL ,
`fichier` VARCHAR( 200 ) NOT NULL ,
`ordre` INT( 2 ) NOT NULL ,
`actif` INT( 2 ) NOT NULL ,
`emplacement` INT( 2 ) NOT NULL
) ENGINE = MYISAM ;");
$db->sql_query("ALTER TABLE `immo_bloc` ADD `plugins` VARCHAR( 100 ) NOT NULL ");
$db->sql_query("ALTER TABLE `immo_bloc` ADD `contenu` TEXT NOT NULL ");
echo '<li>Table immo_bloc creee</li>';
#
# Contenue
#
$db->sql_query("
INSERT INTO `immo_bloc` (`id`, `name`, `fichier`, `ordre`, `actif`, `emplacement`, `plugins`, `contenu`) VALUES
(1, 'recherche', 'bloc/bloc_recherche.php', 0, 1, 4, '', ''),
(2, 'navigation', 'bloc/bloc_navigation.php', 1, 1, 4, '', '');");
#
#   IMMO_BLOC_DISPONIBLE
#
$db->sql_query("
CREATE TABLE `immo_bloc_disponible` (
`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`nom` VARCHAR( 100 ) NOT NULL ,
`fichier` VARCHAR( 200 ) NOT NULL ,
`description` VARCHAR( 200 ) NOT NULL ,
`plugins` VARCHAR( 100 ) NOT NULL
) ENGINE = MYISAM ;");
#
#   CONTENU
#
$db->sql_query("
INSERT INTO `immo_bloc_disponible` (`id`, `nom`, `fichier`, `description`, `plugins`) VALUES
(1, 'Navigation', 'bloc/bloc_navigation.php', 'Bloc navigation Unique', 'Systeme'),
(2, 'Recherche', 'bloc/bloc_recherche.php', 'Bloc de recherche Unique', 'Systeme');");
#
# IMMO_GROUPE
#
$db->sql_query("
CREATE TABLE `immo_groupe` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`nom` VARCHAR( 200 ) NOT NULL ,
`description` VARCHAR( 200 ) NOT NULL ,
`poid` INT NOT NULL ,
`images` VARCHAR( 200 ) NOT NULL ,
`droit_sup` INT NOT NULL 
) ENGINE = MYISAM ;");
#
# CONTENU IMMO GROUPE
#
$db->sql_query("
INSERT INTO `immo_groupe` (
`id` ,
`nom` ,
`description` ,
`poid` ,
`images` ,
`droit_sup` 
)
VALUES (
NULL , 'administrateur', 'Groupe d administration', '0', '', '1'
), (
NULL , 'utilisateur', 'Utilisateur immophp', '0', '', '0'
);");
#
#   IMMO_GROUPE_USER_LINK
#
$db->sql_query("
CREATE TABLE IF NOT EXISTS `immo_groupe_user_link` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `gid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;");
#
#   IMMO_USER_SESSION_ADMIN
#
$db->sql_query("
CREATE TABLE `immo_user_session_admin` (
`id` VARCHAR( 100 ) NOT NULL ,
`token` VARCHAR( 100 ) NOT NULL ,
`uid` INT NOT NULL ,
`date_create` INT( 50 ) NOT NULL ,
`last_used` INT( 50 ) NOT NULL ,
`ip` VARCHAR( 150 ) NOT NULL ,
`page` VARCHAR( 200 ) NOT NULL 
) ENGINE = MYISAM ;");
$db->sql_query("ALTER TABLE `immo_user_session_admin` ADD UNIQUE (
`id` 
)");
#
# IMMO_EVENT_TYPE
#
$db->sql_query("
CREATE TABLE `immo_event_type` (
`id` INT NOT NULL ,
`nom` VARCHAR( 255 ) NOT NULL ,
`description` TEXT NOT NULL 
) ENGINE = MYISAM ;");
$db->sql_query("ALTER TABLE `immo_event_type` ADD PRIMARY KEY ( `id` )"); 
$db->sql_query("ALTER TABLE `immo_event_type` CHANGE `id` `id` INT( 11 ) NOT NULL AUTO_INCREMENT ");
#
#   IMMO_EVENT
#
$db->sql_query("
CREATE TABLE `immo_event` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`titre` VARCHAR( 200 ) NOT NULL ,
`description` TEXT NOT NULL ,
`type` VARCHAR( 200 ) NOT NULL ,
`participant` VARCHAR( 255 ) NOT NULL ,
`lieu` VARCHAR( 255 ) NOT NULL ,
`date_debut` INT( 50 ) NOT NULL ,
`date_debut_fd` DATE NOT NULL ,
`date_fin` INT( 50 ) NOT NULL ,
`date_fin_fd` DATE NOT NULL ,
`duree` INT( 20 ) NOT NULL ,
`public` INT( 2 ) NOT NULL 
) ENGINE = MYISAM ;");
$db->sql_query("ALTER TABLE `immo_event` ADD `link_plugins` DATE NOT NULL ");
$db->sql_query("ALTER TABLE `immo_event` CHANGE `link_plugins` `link_plugins` VARCHAR( 200 ) NOT NULL ");
$db->sql_query("ALTER TABLE `immo_event` ADD `time_debut` TIME NOT NULL ,
ADD `time_fin` TIME NOT NULL ");
#
#   IMMO_USER_DETAIL
#
$db->sql_query("
CREATE TABLE `immo_user_detail` (
`uid` INT NOT NULL ,
`event_config` INT NOT NULL ,
`param_user` INT NOT NULL ,
PRIMARY KEY ( `uid` )
) ENGINE = MYISAM ;");
#
#   CHANGEMENT MULTIPLE
#
$db->sql_query("ALTER TABLE `immo_user_detail` CHANGE `event_config` `event_config` TEXT NOT NULL ,
CHANGE `param_user` `param_user` TEXT NOT NULL ");
$db->sql_query("ALTER TABLE `immo_event` ADD `start_date` DATETIME NOT NULL ,
ADD `end_date` DATETIME NOT NULL ");
$db->sql_query("ALTER TABLE `immo_event` ADD `uid` INT NOT NULL ");
// TRAITEMENT DES CHANGEMENTS PAR RAPPORT AU UTILISATEUR & AUTRE //
# Mise a jour version dans la base
$db->sql_query("UPDATE immo_config SET setting = '1.1.0' WHERE module = 'version'");
# Recuperation des utilisateurs et MAJ
$db->sql_query("INSERT INTO immo_groupe_user_link (uid, gid) VALUES ('1','1')");
$Sql = $db->sql_query("SELECT * FROM immo_user WHERE id != '1'");
while($Utilisateur = $db->sql_fetchobject($Sql))
{
    $db->sql_query("INSERT INTO immo_groupe_user_link (uid, gid) VALUES ('". $Utilisateur->id ."','2')");   
}
$SqlSetting  = $db->sql_query("SELECT setting FROM immo_config WHERE module = 'generale'",'ARRAY');
$temp2 = unserialize($SqlSetting['setting']);
# Gestion setting avec le rajout du page par defaut
$temp = array(
'titre_site'	=>	$temp2['titre_site'],
'keywords'	=>	$temp2['keywords'],
'description_site'	=>	$temp2['description_site'],
'annonce_par_page'	=>	$temp2['annonce_par_page'],
'contenue_accueil'	=>	$temp2['contenue_accueil'],
'googlemap_key'	=>	$temp2['googlemap_key'],
'google_analytics'	=>	$temp2['google_analytics'],
'google_identifiant_site'	=>	$temp2['google_identifiant_site'],
'email_contact'	=>	$temp2['email_contact'],
'footer_text'	=>	$temp2['footer_text'],
'affiche_secteur_annonce'	=>	$temp2['affiche_secteur_annonce'],
'affiche_ville_annonce'	=>	$temp2['affiche_ville_annonce'],
'theme'	=>	$temp2['theme'],
'dvlp_mod'	=>	$temp2['dvlp_mod'],
'map_accueil'	=>	$temp2['map_accueil'],
'url_rewrite'	=>	$temp2['url_rewrite'],
'page_accueil'  =>  $temp2['page_accueil'],
);
$db->sql_query("UPDATE immo_config SET setting = '". serialize($temp) ."' WHERE module = 'generale'");
echo '<div>End update database</div>';
?>